<?php

namespace App\Http\Requests\Admin\Customer\PackCategory;

use App\Http\Requests\ApiRequest;
use App\Services\Utils\Guard;
use Illuminate\Http\UploadedFile;
use Illuminate\Validation\Rule;

/**
 * @property string name
 * @property string priority
 * @property string|UploadedFile image
 */
class PackCategoryStoreRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $customer_id = Guard::customerAdmin()->customer_id;

        $image_rule = is_file($this->image) ? 'required|file' : 'nullable';

        return [
            'name' => ['required', 'string', 'max:'.self::MAX_STRING, Rule::unique('pack_categories')
                ->where('customer_id',  $customer_id)
            ],
            'priority'  => 'nullable|int|between:0,10000',
            'image'     => $image_rule,  // file or string
        ];
    }
}
